import 'package:flutter/material.dart';
import 'package:ytbusiness/utils/helper.dart';
import 'package:ytbusiness/utils/screen_adaptation.dart';
import 'package:ytbusiness/widgets/widgets.dart';

class PushRepairCategory extends StatefulWidget {
  //{type,title}
  final Map<String, dynamic> arguments;

  const PushRepairCategory({Key key, this.arguments}) : super(key: key);

  @override
  _PushRepairCategoryState createState() => _PushRepairCategoryState();
}

class _PushRepairCategoryState extends State<PushRepairCategory> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: customAppBar(context, title: widget.arguments["title"] as String),
      body: CustomScrollView(
        slivers: [
          //推修列表
          SliverList(
              delegate: SliverChildBuilderDelegate((context, index) {
            return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  switch (int.parse(widget.arguments["type"] as String)) {
                    case 0:
                      urlPush(context,
                          "yuntu://push_repair_details?title=${widget.arguments["title"]}");
                      break;
                    case 1:
                      urlPush(context,
                          "yuntu://in_loss_assessment?title=${widget.arguments["title"]}");
                      break;
                    case 2:
                      urlPush(context,
                          "yuntu://in_maintenance?title=${widget.arguments["title"]}");
                      break;
                    case 3:
                      urlPush(context,
                          "yuntu://wait_back_bill?title=${widget.arguments["title"]}");
                      break;
                    case 4:
                      urlPush(context,
                          "yuntu://repair_await_settlement?title=${widget.arguments["title"]}");
                      break;
                    case 5:
                      urlPush(context,
                          "yuntu://repair_refunded?title=${widget.arguments["title"]}");
                      break;
                    case 6:
                      urlPush(context,
                          "yuntu://await_balance?title=${widget.arguments["title"]}");
                      break;
                    case 7:
                      urlPush(context,
                          "yuntu://repair_have_settlement?title=${widget.arguments["title"]}");
                      break;
                    case 8:
                      urlPush(context,
                          "yuntu://repair_withdrawn?title=${widget.arguments["title"]}");
                      break;
                  }
                },
                child: _pushRepairItem(
                    state: widget.arguments["title"] as String));
          }, childCount: 10)),
        ],
      ),
    );
  }

  Widget _pushRepairItem({String state}) {
    return Container(
      margin: EdgeInsets.only(
          left: setWidth(15), right: setWidth(15), top: setWidth(15)),
      padding: EdgeInsets.only(
          left: setWidth(14), right: setWidth(14), bottom: setWidth(18)),
      decoration: BoxDecoration(
          color: Colors.white, borderRadius: BorderRadius.circular(2)),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          //处理编号
          _dealingNum(num: "AE11232498", state: state),
          //车辆牌号
          _carNumber(type: "A98U89", time: "2020-01-21 10:10"),
          //车辆型号
          _carInfo("路虎极光 雅致版GF236"),
        ],
      ),
    );
  }

  //处理编号
  Widget _dealingNum({String num, String state}) {
    return Container(
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(
                text: TextSpan(children: [
              TextSpan(
                  text: "处理编号:",
                  style:
                      TextStyle(color: Color(0xff999999), fontSize: setSp(14))),
              WidgetSpan(
                  child: SizedBox(
                width: setWidth(3),
              )),
              TextSpan(
                  text: num,
                  style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(14))),
            ])),
          ),
          Row(
            children: [
              Container(
                height: setWidth(18.5),
                width: setWidth(32),
                color: Color(0xffE5E5E5),
              ),
              SizedBox(
                width: setWidth(10.5),
              ),
              Container(
                child: Text(state,
                    style: TextStyle(
                        color: Color(0xffFF921A), fontSize: setSp(13))),
              ),
            ],
          )
        ],
      ),
    );
  }

  //车辆牌号
  Widget _carNumber({String type, String time}) {
    return Container(
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(
                text: TextSpan(children: [
              TextSpan(
                  text: "车辆牌号:",
                  style:
                      TextStyle(color: Color(0xff999999), fontSize: setSp(14))),
              WidgetSpan(
                  child: SizedBox(
                width: setWidth(3),
              )),
              TextSpan(
                  text: type,
                  style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(14))),
            ])),
          ),
          Container(
            child: Text(time,
                style:
                    TextStyle(color: Color(0xff999999), fontSize: setSp(13))),
          )
        ],
      ),
    );
  }

  //车辆型号
  Widget _carInfo(String info) {
    return Container(
      margin: EdgeInsets.only(top: setWidth(17)),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: [
          Expanded(
            child: RichText(
                text: TextSpan(children: [
              TextSpan(
                  text: "车辆型号:",
                  style:
                      TextStyle(color: Color(0xff999999), fontSize: setSp(14))),
              WidgetSpan(
                  child: SizedBox(
                width: setWidth(3),
              )),
              TextSpan(
                  text: info,
                  style:
                      TextStyle(color: Color(0xff323232), fontSize: setSp(14))),
            ])),
          ),
        ],
      ),
    );
  }
}
